TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../../config.mk

# Inputs
TABLE_SCRIPT := $(TASK_DIR)/src/dosage_heterogeneity_output.do
DOSAGE_MODEL := $(TASK_DIR)/../../run_stata_dosage_model/output/dosage_heterogeneity.dta
DOSAGE_OUTPUT_DIR := $(TASK_DIR)/../../run_stata_dosage_model/output/

## Only calibration plot:
PLOT_SCRIPT := $(TASK_DIR)/src/dosage_heterogeneity_calibration.do
PARAM_FILE := $(DOSAGE_OUTPUT_DIR)/load_parameters.do
XSECTION_ANALYSIS_FILE_CSV := $(DOSAGE_OUTPUT_DIR)/readi_outcomes_roster_up_to_date.csv

# Outputs
OUTPUT_TABLE := $(OUT_DIR)/predicted_dosage_contents_up_to_date.tex
OUTPUT_PLOT := $(OUT_DIR)/dosage_calib_plot_up_to_date.pdf

$(OUTPUT_TABLE): $(TABLE_SCRIPT) $(DOSAGE_MODEL) $(DOSAGE_OUTPUT_DIR)/*
	@mkdir -p $(OUT_DIR)
	stata -b do $(TABLE_SCRIPT) $(DOSAGE_MODEL) $(DOSAGE_OUTPUT_DIR) $(OUTPUT_TABLE)
	@cp $(OUT_DIR)/*up_to_date.tex $(PAPER_OUT_DIR)

$(OUTPUT_PLOT): $(PLOT_SCRIPT) $(PARAM_FILE) $(XSECTION_ANALYSIS_FILE_CSV)
	@mkdir -p $(OUT_DIR)
	stata -b do $(PLOT_SCRIPT) $(PARAM_FILE) $(XSECTION_ANALYSIS_FILE_CSV) $(OUTPUT_PLOT)
	@cp $(OUT_DIR)/*up_to_date.pdf $(PAPER_OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUTPUT_TABLE) $(OUTPUT_PLOT)

clean:
	rm -rf $(OUT_DIR)/*up_to_date*


